<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <!--        <a-row :gutter="24">-->

        <a-row :gutter="24" type="flex" align="middle">
          <a-col :xl="6" :lg="4" :md="6" :sm="10">
            <!--            v-has="'orderId:select'"-->
            <a-form-item label="城市服务商" style="margin-right: 10px" v-has="'userAppeal:select'">
              <serveSelect @selectClick="selectClick" :value="queryParam.agencyCode"></serveSelect>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="4" :md="6" :sm="10">
            <a-form-item label="用户编号" style="margin-right: 20px">
              <a-input style="width: 200px" placeholder="用户编号" v-model="queryParam.userId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="4" :md="6" :sm="10">
            <a-form-item label="开始时间" style="margin-right: 10px">
              <a-date-picker v-model="queryParam.startTime" :valueFormat="'YYYY-MM-DD'" @change="startChange" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="4" :md="6" :sm="10">
            <a-form-item label="结束时间" style="margin-right: 10px">
              <a-date-picker
                v-model="queryParam.endTime"
                :valueFormat="'YYYY-MM-DD'"
                @change="endChange"
                :disabled-date="disabledDate"
              />
            </a-form-item>
          </a-col>

          <!---->
          <a-col :xl="6" :lg="4" :md="6" :sm="10">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <!--    <div class="table-operator">-->
    <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
    <!--      <a-button type="primary" icon="download" @click="handleExportXls('申诉功能')">导出</a-button>-->
    <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
    <!--        <a-button type="primary" icon="import">导入</a-button>-->
    <!--      </a-upload>-->
    <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
    <!--        <a-menu slot="overlay">-->
    <!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
    <!--        </a-menu>-->
    <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
    <!--      </a-dropdown>-->
    <!--    </div>-->

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <template slot="avatarUrl" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatarUrl)" />
          </div>
        </template>
        <template slot="img" slot-scope="text, record">
          <div style="height: 100px; width: 50px" class="anty-img-wrap">
            <j-image-upload v-if="record.img" text="上传" disabled v-model="record.img"></j-image-upload>
          </div>
        </template>

        <template slot="disposeResult" slot-scope="text, record">
          <a-tooltip placement="topLeft" :title="text">
            <div style="max-width: 10em; line-height: 1.5; overflow: hidden; text-overflow: ellipsis">
              {{ record.disposeResult }}
            </div>
          </a-tooltip>
        </template>
        <template slot="descriptionContent" slot-scope="text, record">
          <a-tooltip placement="topLeft" :title="text">
            <div style="max-width: 10em; line-height: 1.5; overflow: hidden; text-overflow: ellipsis">
              {{ record.descriptionContent }}
            </div>
          </a-tooltip>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-has="'userAppeal:update'" v-if="record.status === 0" @click="handleEdit(record)">处理</a>
          <a-divider type="vertical" />
          <a-dropdown v-has="'userAppeal:delete'">
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <xhdjUserAppeal-modal ref="modalForm" @ok="modalFormOk"></xhdjUserAppeal-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import XhdjUserAppealModal from './modules/XhdjUserAppealModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import serveSelect from '@/components/serveSelect.vue'
import { getFileAccessHttpUrl } from '@api/manage'

export default {
  name: 'XhdjUserAppealList',
  mixins: [JeecgListMixin],
  components: {
    XhdjUserAppealModal,
    serveSelect
  },
  data () {
    return {
      description: '申诉功能管理页面',
      // 表头
      columns: [
        {
          title: '用户编号',
          align: 'center',
          dataIndex: 'userId'
        },
        {
          title: '用户手机',
          align: 'center',
          dataIndex: 'phone'
        },
        {
          title: '用户头像',
          align: 'center',
          dataIndex: 'avatarUrl',
          scopedSlots: { customRender: 'avatarUrl' }
        },
        {
          title: '投诉时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '投诉内容',
          align: 'center',
          dataIndex: 'descriptionContent',
          scopedSlots: { customRender: 'descriptionContent' }
        },
        {
          title: '图片',
          align: 'center',
          dataIndex: 'img',
          scopedSlots: { customRender: 'img' }
        },
        {
          title: '申诉类型',
          align: 'center',
          dataIndex: 'appealType'
        },
        {
          title: '处理结果',
          align: 'center',
          dataIndex: 'disposeResult',
          scopedSlots: { customRender: 'disposeResult' }
        },
        {
          title: '处理时间',
          align: 'center',
          dataIndex: 'updateTime'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          customRender: (text, record) => {
            return record.status === 0 ? '待处理' : '已处理'
          }
        },
        {
          title: '操作人',
          align: 'center',
          dataIndex: 'updateBy'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/user/xhdjUserAppeal/list',
        delete: '/user/xhdjUserAppeal/delete',
        deleteBatch: '/user/xhdjUserAppeal/deleteBatch',
        exportXlsUrl: '/user/xhdjUserAppeal/exportXls',
        importExcelUrl: '/user/xhdjUserAppeal/importExcel'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    startChange (value) {
      if (value) {
        this.queryParam.startTime = value + ' 00:00:00'
      } else {
        this.queryParam.startTime = value
      }
    },
    endChange (value) {
      if (value) {
        this.queryParam.endTime = value + ' 23:59:59'
      } else {
        this.queryParam.endTime = value
      }
    },
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },

    selectClick (value) {
      this.queryParam.agencyCode = value
      this.searchQuery()
    },
    disabledDate (time) {
      return new Date(time).getTime() < new Date(this.queryParam.startTime).getTime()
    },
    disabledDates (time) {
      return new Date(time).getTime() < new Date(this.queryParam.startPayTime).getTime()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
